//加载方法
$(function (){
    $("#wuliao").hide();
    $.ajax({
        url:"/TYMDes/cxshenhe",
        type:"get",
        contentType:"application/json;charset=utf-8",
        dataType:"json",
        success:function (data) {
            console.log(data);
            $("#weishenhe").html(data.weishenhe);
            $("#tongguo").html(data.tongguo);
            $("#butongguo").html(data.butongguo);
        }
    })
    //模糊查询的方法，生成表格
    $("#tableinfo").bootstrapTable({
        method:"get",
        contentType:"application/json;charset=utf-8",
        url: "/TYMDes/selcx",
        striped: true,
        pageNumber:1,
        pagination:true,
        sidePagination:"server",//设置服务端分页还是客户端分页
        pageSize:3,//页大小
        pageList:[2,3,5],//每页显示的条数
        queryParams:function (params) {
            return {
                pageNum: (params.offset / params.limit) + 1,
                pageSize:params.limit,
                productName:$("#productName").val()
            }
        },
        columns:[
            {title:'设计单编号',field:'designId',align:'center'},
            {title:'产品名称',field:'productName',align:'center'},
            {title:'登记人',field:'register',align:'center'},
            {title:'登记时间',field:'registerTime',align:'center'},
            {title:'备注',field:'moduleDescribe',align:'center'},
            {title:'操作',field:'designModuleId',align:'center',
                formatter:function (value,row,index) {
                    let btn="<button class='btn btn-info' onclick='kan("+value+")'>查看</button>";
                    return btn;
                }
            },
        ]
    })
})

//点击去审核
let applyId1="";
function kan(applyId){
    $("#table").hide();
    $("#wuliao").show();
    $("#remark").html("");
    applyId1=applyId;
    $.ajax({
        url: "/TYMDes/selbyoneshenhe/"+applyId,
        type:"post",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        success:function (data){
            console.log(data)
            $("#designer").html(data.designer);
            $("#shenhe").html(parent.document.getElementsByClassName("user_name")[0].innerHTML);
            $("#bianhao").html(data.designId);
            $("#mingcheng").html(data.productName);
            $("#remark").html(data.moduleDescribe);
            let tr ="";
            for (let i = 0; i < data.dList.length; i++) {
                let unit = data.dList[i].amountUnit;
                if (unit==undefined){
                    unit="";
                }

                tr +="<tr>\n" +
                    "                <td>"+data.dList[i].productName+"</td>\n" +
                    "                <td>"+data.dList[i].productId+"</td>\n" +
                    "                <td>"+data.dList[i].productDescribe+"</td>\n" +
                    "                <td class='shuliang'>"+data.dList[i].amount+"</td>\n" +
                    "                <td>"+unit+"</td>\n" +
                    "                <td>"+data.dList[i].costPrice+"</td>\n" +
                    "                <td class=\"xiaoji\">"+data.dList[i].subtotal+"</td>\n" +
                    "            </tr>";
            }
            $("#tbody").html(tr);

            //获取数量和小计
            let xiaoji = $(".xiaoji");
            let amounts = $(".shuliang");

            //定义总数量和总金额
            let totalCount=0;
            let totalPrice=0;
            amounts.each(function (i,e){
                totalCount+=parseInt($(e).html());
            })
            xiaoji.each(function (i,e){
                totalPrice+=parseFloat($(e).html());
            })

            $("#totalCount").html(totalCount);
            $("#totalPrice").html(totalPrice);
        }
    })
}

function fan() {
    $("#table").show();
    $("#wuliao").hide();
    $("#tableinfo").bootstrapTable("refresh");
}

function refreshs() {
    $("#tableinfo").bootstrapTable("refresh");
}